using B.S.Ingredients.Infartructrue;
using B.S.Ingredients.Infartructrue.Impment;
using B.S.Ingredients.Infartructrue.Interfaces;
using Microsoft.EntityFrameworkCore;
using NLog.Web;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddDbContext<MyDbContext>(a => a.UseMySql(
    builder.Configuration.GetConnectionString("Conn"), ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("Conn"))
    ));

builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));
builder.Services.AddMediatR(o => o.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
builder.Host.UseNLog();

var app = builder.Build();

app.UseCors(a => a.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseAuthorization();

app.MapControllers();

app.Run();
